// MCP Client Base Class
// MCP客户端基类
class MCPClient {
  constructor(name) {
    this.name = name;
    this.connectedServers = new Map();
  }

  // Connect to an MCP server
  // 连接到MCP服务器
  connectToServer(serverName, server) {
    this.connectedServers.set(serverName, server);
  }

  // Get data from a connected server
  // 从连接的服务器获取数据
  getDataFromServer(serverName, dataSource) {
    const server = this.connectedServers.get(serverName);
    if (server) {
      if (dataSource === 'waterQuality') {
        return server.getWaterQualityData();
      } else if (dataSource === 'chemicalDosage') {
        return server.getChemicalDosageData();
      }
    }
    return null;
  }

  // Send command to a connected server
  // 向连接的服务器发送命令
  sendCommandToServer(serverName, command) {
    const server = this.connectedServers.get(serverName);
    if (server) {
      return server.controlChemicalDosage(command);
    }
    return false;
  }

  // Initialize the client
  // 初始化客户端
  initialize() {
    console.log(`${this.name} MCP Client initialized`);
  }
}

module.exports = MCPClient;